/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package edu.office.applicationRepository;


import edu.office.entities.Registeruser;
import edu.office.entities.Roleinfo;
import edu.office.entities.User;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;
import jakarta.inject.Named;

/**
 *
 * @author Administrator
 */
@Named("registeruserRepositoryA")
@ApplicationScoped
public class RegisteruserRepository extends ApplicationCommonRepository<Registeruser>{
@Inject
RoleinfoRepository roleinfoRepository;
    public String myCreate(User user) {
        //检查用户名是否存在，如果存在，则通知需要重新注册
        String sqlString = "select * from ";
        if (roleinfoRepository.isParent(user.getRoleId())) {
            sqlString += " parent ";
        } else if (roleinfoRepository.isTeahcer(user.getRoleId())) {
            sqlString += " teacher_admin ";
        } else if (roleinfoRepository.isStudent(user.getRoleId())) {
            sqlString += " student ";
        }
        sqlString += " where name='" + user.getName().trim() + "'";
        if (find(sqlString).list().isEmpty()) {
            create((Registeruser) user);
            return "Succeed";
        } else {
            return "Already Exist";
        }
    }
}
